using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsCE.Forms;

namespace ManagedService
{
    /// <summary>
    /// This class is a Helper class for Sending Window Messages
    /// </summary>
    public static class ServiceMessageHelper
    {
        /// <summary>
        /// Sends message to the message window and wait until Microsoft.WindowsCE.Forms.MessageWindows.WndProc(Microsoft.WindowsCE.Forms.Message) method has proceed
        /// </summary>
        /// <param name="serviceGuid">Name of the window</param>
        /// <param name="message">Windows message</param>
        /// <param name="Wparam">W parameter</param>
        /// <param name="Lparam">L parameter</param>
        public static void SendMessage(string serviceGuid, int message, int Wparam, int Lparam)
        {
            IntPtr hwnd = SystemCalls.FindWindow(IntPtr.Zero, serviceGuid);
            Message msg = Message.Create(hwnd, message, (IntPtr)Wparam, (IntPtr)Lparam);

            MessageWindow.SendMessage(ref msg);
        }

        /// <summary>
        /// Sends message to the message window and wait until Microsoft.WindowsCE.Forms.MessageWindows.WndProc(Microsoft.WindowsCE.Forms.Message) method has proceed
        /// </summary>
        /// <param name="serviceGuid">Name of the window</param>
        /// <param name="message">Windows message</param>
        public static void SendMessage(string serviceGuid, int message)
        {
            SendMessage(serviceGuid, message, 0, 0);
        }

        /// <summary>
        /// Sends message to the message window and return immediately
        /// </summary>
        /// <param name="serviceGuid">Name of the window</param>
        /// <param name="message">Windows message</param>
        /// <param name="Wparam">W parameter</param>
        /// <param name="Lparam">L parameter</param>
        public static void PostMessage(string serviceGuid, int message, int Wparam, int Lparam)
        {
            IntPtr hwnd = SystemCalls.FindWindow(IntPtr.Zero, serviceGuid);
            Message msg = Message.Create(hwnd, message, (IntPtr)Wparam, (IntPtr)Lparam);

            MessageWindow.PostMessage(ref msg);
        }

        /// <summary>
        /// Sends message to the message window and return immediately 
        /// </summary>
        /// <param name="serviceGuid">Name of the window</param>
        /// <param name="message">Windows message</param>
        public static void PostMessage(string serviceGuid, int message)
        {
            PostMessage(serviceGuid, message, 0, 0);
        }
    }
}
